/*
 * DatagramBuilder Library: serialize/deserialize data to/from datagram
 * Copyright (C) 2008 Rakov Ilya <RakovIlya@gmail.com>
 *
 * This library can be distributed under the terms of the GNU LGPLv2.
 * See the file COPYING.LIB.
 */


#ifndef DATAGRAM_ENDOFDATAIMPL_H_
#define DATAGRAM_ENDOFDATAIMPL_H_


/**
 * @file EndOfDataImpl.h
 *
 * @brief EndOfData implementation file
 *
 * @date Dec 2, 2008
 * @author Rakov Ilya
 */


bool EndOfData::operator ==( EndOfData ) const
{
  return true;
}


bool EndOfData::operator !=( EndOfData ) const
{
  return false;
}


template< class CharType, class CharTrait >
std::basic_ostream< CharType, CharTrait >&
operator <<( std::basic_ostream<CharType, CharTrait> &out, const EndOfData )
{
  out << "end";

  return out;
}


/*
 * This explicit specialization of the SerializeImpl< class T > provides
 * an ability to serialize/deserialize the EndOfData type.
 */
template <>
struct SerializeImpl< EndOfData >
{

  static inline void SerializeTag( Builder &builder )
  {
    /* do nothing */
  }


  static inline void Serialize( Builder &builder, const EndOfData )
  {
    /* do nothing */
  }


  static inline void DeSerializeTag( Parser &parser )
  {
    /* do nothing */
  }


  static inline void DeSerialize( Parser &parser, EndOfData )
  {
    if ( !parser.IsTreated() )
      throw deserialize_error( "data is not terminated at that position" );
  }

};


#endif /* DATAGRAM_ENDOFDATAIMPL_H_ */
